<template>
  <view>
    <tm-radio-group v-model="selectObj.selectValue" model="buttn">
      <tm-radio
        :value="item"
        v-for="item in sourceArr"
        :color="selectObj.selectValue != item ? '#7c90ad' : 'primary'"
        :round="2"
        :label="item"
        :key="item"
      ></tm-radio>
    </tm-radio-group>
  </view>
</template>

<script setup lang="ts">
import { reactive, watch } from "vue";
const selectObj = reactive({
  selectValue: "",
  defaultVal: ""
});
const props = defineProps({
  sourceArr: {
    type: Array,
    required: true
  },
  defaultSelect: {
    type: String,
    default: ""
  }
});

//当前选中的项
function getSelectValue() {
  return selectObj.selectValue;
}

//重置默认选项
function resetValue() {
  selectObj.selectValue = props.defaultSelect;
}

defineExpose({
  getSelectValue,
  resetValue
});

watch(
  () => props.defaultSelect,
  () => {
    selectObj.defaultVal = props.defaultSelect;
  }
);
</script>

<style></style>
